package packageParser;

import java.io.BufferedWriter;
import java.io.ObjectOutputStream;
import java.util.List;
import java.util.Map;

import packageHandler.PackageHandlerForServer;
import protocol.DataPackage;
import util.DBUtil;

//这里可以取出来一个PackageHandler
public class PackageParserForServer {
	public static boolean packageParse(Map<String, BufferedWriter> socketList, List<String> userList, DataPackage pack){
		
		DataPackage.MessageType type = pack.getMessageType();
		
		//判断用户发送过来的message类型，并根据不同的类型，服务器做出相应的动作
		
		//转发package
		if(type == DataPackage.MessageType.MESSAGE || type == DataPackage.MessageType.SHAKE){
			PackageHandlerForServer.transmitMassageForClient(socketList, userList, pack);
		}
		//通知所有用户有一个用户下线
		else if (type == DataPackage.MessageType.LOGOUT){
			DBUtil.logout(pack.getFromName());
			PackageHandlerForServer.clientLogout(socketList, userList, pack);
			return false;
		}
		return true;
	}
}
